"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getPlainText = getPlainText;

var _react = _interopRequireDefault(require("react"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * 提取子结点中纯文本
 */
function getPlainText(node) {
  var text = [];

  var traverse = function traverse(children) {
    if (!children) {
      return;
    }

    _react.default.Children.forEach(children, function (child) {
      if ( /*#__PURE__*/_react.default.isValidElement(child) && child.props.children) {
        traverse(child.props.children);
      } else if (typeof child === 'number' || typeof child === 'string') {
        text.push(String(child));
      }
    });
  };

  traverse(node);
  return text.join(' ');
}